package com.weibo.survey.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.weibo.survey.dao.BaseDao;
import com.weibo.survey.domain.User;
import com.weibo.survey.service.UserService;
import com.weibo.survey.utils.ValidateUtils;

@Service("userService")
public class UserServiceImpl extends BaseServiceImpl<User> implements UserService {

	@Resource(name = "userDao")
	public void setBaseDao(BaseDao<User> baseDao) {
		super.setBaseDao(baseDao);
	}

	@Override
	public boolean isRegister(String email) {
		List<User> users = this.getEntitiesByHql("from User u where u.email=?", email);
		return ValidateUtils.isValidate(users);
	}

	@Override
	public User login(User user) {
		return getEntityByHql("from User u where u.email=? and u.password=?",//
				user.getEmail(), user.getPassword());
	}
}
